const express = require('express'),
    cookieParser = require('cookie-parser'),
    session = require('express-session'),
    path = require('path');
const app = express();


app.use(session({
    secret: 'www.ydoo.cn',
    resave: false,
    saveUninitialized: true,
    cookie: {
        maxAge: 1000 * 60 * 60 * 20, //单位ms，session过期时间2小时
        secure: false,
    }
}))



//app.set('views', `${__dirname}/views`); //设置html目录
//app.set('views', '/views'); //设置html目录
app.set('view engine', 'html'); //设置html模板引擎
app.set('views', __dirname + '/views')
app.engine('html', require('ejs').renderFile); ////设置ejs用html

//app.use(express.static(path.join('public'))); 
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static('public')); //设置静态目录


//拦截所有请求，检查session
app.use(function(req, res, next) {
    var url = req.url;
    if (url != "/" && url != "/login" && url != "/dologin" && !req.session.ddt) {
        return res.redirect("/");
    }
    next();
});


app.use(function(err, req, res, next) {
    console.log(err.message);
});


app.use(express.urlencoded({ extended: true })); //对post请求处理


app.get('/', (req, res) => {
    res.render('./pcpages/supervision/sup_login.html', { msg: '' })
})

app.use('/dologin', require('./routes/dologin.js'));
app.use('/loginOut', require('./routes/loginOut.js'));


app.get('/main', (req, res) => {
    let orgName = req.session.orgName;
    let name = req.session.name;
    let orgOID = req.session.orgOID;
    let ddt = req.session.ddt;
    res.render('./pcpages/supervision/sup_main.html', { orgName: orgName, name: name })
})

app.use('/main/index', require('./module/supervision/index.js')); //按发包查询
app.use('/main/oindex', require('./module/supervision/oindex.js')); //按工单查询
app.use('/main/pindex', require('./module/supervision/pindex.js')); //按分包方查询
app.use('/main/uindex', require('./module/supervision/uindex.js')); //按接单员查询
app.use('/main/payindex', require('./module/supervision/payindex.js')); //按支付查询




app.use('/proof', require('./module/supervision/proof.js')); //查询商户打款凭证
app.use('/invshow', require('./module/supervision/invshow.js')); //查询平台开具给商户的发票
app.use('/invsumuser', require('./module/supervision/invsumuser.js')); //查询接单员
app.use('/invpay', require('./module/supervision/invpay.js')); //查询支付详情
app.use('/paypdf', require('./module/supervision/paypdf.js')); //查询接单员支付回单



app.use('/showOrderUser', require('./module/supervision/showOrderUser.js')); //oindex页面查询
app.use('/wgOrderUser', require('./module/supervision/wgOrderUser.js')); //oindex页面查询
app.use('/payedlist', require('./module/supervision/payedlist.js')); //oindex页面查询
// app.use('/showOrderUser', require('./module/supervision/showOrderUser.js')); //oindex页面查询


app.listen(2003);
console.log('服务器解析地址： http://127.0.0.1:2003/');